#include <Misc/Config.hpp>


Config *Config::configInstance = 0;

Config::Config(){

	setDefault();

}

Config *Config::instance(){
	if(Config::configInstance == 0){
		Config::configInstance = new Config();
	}
	return Config::configInstance;
}

void Config::parseArguments(int argc, char **argv){

	if(argc > 1){

		for(int i=1; i<argc; i++){

			std::string arg(argv[i]);

			if(!arg.compare("-p")){

				std::istringstream(argv[i+1]) >> port;

			}else if(!arg.compare("-a")){

				std::istringstream(argv[i+1]) >> address4;
				address6 = address4;

			}else if(!arg.compare("-l")){

				std::istringstream(argv[i+1]) >> logFile;

			}else if(!arg.compare("-in")){

				std::istringstream(argv[i+1]) >> inputFile;

			}else if(!arg.compare("-out")){

				std::istringstream(argv[i+1]) >> outputFile;

			}else if(!arg.compare("-IPv6")){

				ipv6Flag = true;

			}else if(!arg.compare("-h") || !arg.compare("--help")){

				helpFlag = true;

			}

		}

	}else{
		/*
		 * Set default values
		 */
		setDefault();
	}


}

void Config::setDefault(){

	address4 = "127.0.0.1";
	address6 = "::1";
	port = 5000;

	inputFile = "/tmp/ibrc-client-input";
	outputFile = "/tmp/ibrc-client-output";

	logFile = "/tmp/ibrc-client.log";

	helpFlag = false;
	ipv6Flag = false;

}

std::string& Config::getInputFile(){
	return inputFile;
}

std::string& Config::getOutputFile(){
	return outputFile;
}

std::string& Config::getAddress4(){
	return address4;
}

std::string& Config::getAddress6(){
	return address6;
}

int Config::getPort(){
	return port;
}

std::string& Config::getLogFile(){
	return logFile;
}

bool Config::isHelpFlag(){
	return helpFlag;
}

bool Config::isIPv6Flag(){
	return ipv6Flag;
}
